/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Trabalho3.RegrasPasswordChecker02;

import Trabalho3.RuleFactory;

/**
 *
 * @author geraldo
 */
public class RegraDescontoSequenciaLetras implements RuleFactory{
    final String LITERAIS = "abcdefghijlmnopqrstuvwxyz";
    final int FATOR_DESCONTO_SEQUENCIA_LETRAS = -3;
    String password;

    public RegraDescontoSequenciaLetras(String password) {
        this.password = password;
    }
    
    @Override
    public int calcularRegra() {
        return this.calcularSequenciasDeLiterais()* FATOR_DESCONTO_SEQUENCIA_LETRAS;
        
    }
    
    
    public int calcularSequenciasDeLiterais(){
       String senha = password.toLowerCase();
       int qtdeSeqLiterais =0;
       String literais = this.LITERAIS;
            for (int s=0; s < 22; s++) {//<==== Literais sequenciais
		String sFwd = literais.substring(s,s+3);
		String sRev = new StringBuffer(sFwd).reverse().toString();
                if (senha.indexOf(sFwd) != -1 || senha.indexOf(sRev) != -1) { 
                    qtdeSeqLiterais++;
                    }
		}
       return qtdeSeqLiterais;
   }
}

